import React from 'react';
import {
  TouchableOpacity,
  TouchableOpacityProps,
  StyleSheet,
} from 'react-native';
// import _ from 'lodash';

const Touchable: React.FC<TouchableOpacityProps> = React.memo(
  ({style, onPress, ...reset}) => {
    const touchableStyle = reset.disabled ? [style, styles.disabled] : [style];
    // // lodash节流函数
    // let throttleOnPress = useCallback(() => {
    //   console.log('typeof onPresstypeof onPresstypeof onPress', typeof onPress);
    //   if (typeof onPress === 'function') {
    //     const clickCallback = _.throttle(
    //       onPress, //节流函数
    //       1000, //节流时间
    //       {leading: true}, //是否在节流之前执行
    //     );
    //     console.log(clickCallback);
    //     return clickCallback;
    //   } else {
    //     return undefined;
    //   }
    // }, [onPress]);

    return (
      <TouchableOpacity
        activeOpacity={0.8}
        {...reset}
        style={touchableStyle}
        onPress={onPress}
      />
    );
  },
);

const styles = StyleSheet.create({
  disabled: {
    opacity: 0.5,
  },
});

export default Touchable;
